//
//  HomeCell.m
//  YearsProgram
//
//  Created by 王理朝 on 2019/5/5.
//  Copyright © 2019 王理朝. All rights reserved.
//

#import "HomeCell.h"

@interface HomeCell ()

@property (strong, nonatomic) UIView *leftView;

@property (strong, nonatomic) UILabel *titleLabel;

@property (strong, nonatomic) UILabel *leftLabel;

@property (strong, nonatomic) UIView *backView;

@property (strong, nonatomic) UIView *line;

@end

@implementation HomeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self makeCell];
    }
    return self;
}

- (void)makeCell {
    
    self.backgroundColor = DefaultBackColor;
    
    [self addSubview:self.backView];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.backView addSubview:self.leftView];
    CGFloat pointWidth = 10;
    self.leftView.layer.cornerRadius = pointWidth / 2.0;
    [self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.backView.mas_centerY);
        make.left.equalTo(self.backView).offset(10);
        make.width.height.equalTo(pointWidth);
    }];
    
//    [self.backView addSubview:self.leftLabel];
//    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.equalTo(self.leftView);
//    }];
    
    [self.backView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftView.mas_right).offset(10);
        make.top.bottom.right.equalTo(self.backView).offset(UIEdgeInsetsMake(0, 0, 0, 10));
    }];
    
    
    [self.backView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.backView).offset(UIEdgeInsetsMake(0, 10, 0, 10));
        make.height.equalTo(1);
    }];
}

- (void)showCell:(NSString *)content {
    self.titleLabel.text = content;
//    self.leftLabel.text = dataDic[@"day"];
}

- (UIView *)backView {
    if (!_backView) {
        _backView = [[UIView alloc] init];
        _backView.backgroundColor = [UIColor whiteColor];
    }
    return _backView;
}

- (UIView *)leftView {
    if (!_leftView) {
        _leftView = [[UIView alloc] init];
        _leftView.backgroundColor = randomColor;
    }
    return _leftView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = RegularMiddelFont;
    }
    return _titleLabel;
}

- (UILabel *)leftLabel {
    if (!_leftLabel) {
        _leftLabel = [[UILabel alloc] init];
        _leftLabel.font = MediumBigFont;
        _leftLabel.backgroundColor = [UIColor clearColor];
        _leftLabel.textColor = [UIColor whiteColor];
        _leftLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _leftLabel;
}

- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = DefaultBackColor;
    }
    return _line;
}

@end
